package org.example.controller;

import org.example.annotation.CheckPermission;
import org.example.pojo.domain.Feedback;
import org.example.result.Result;
import org.example.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    // 根据文物ID获取所有反馈
    @CheckPermission({"visitor","curator","admin"})
    @GetMapping("/artifact/{artifactId}")
    public Result listFeedbacks(@PathVariable Integer artifactId) {
        List<Feedback> feedbacks = feedbackService.listFeedbacksByArtifact(artifactId);
        return Result.success("文物ID("+artifactId+")获取所有反馈",feedbacks);
    }

    // 根据反馈ID获取反馈详情
    @CheckPermission({"visitor","curator","admin"})
    @GetMapping("/{feedbackId}")
    public Result getFeedback(@PathVariable Integer feedbackId) {
        Feedback feedback = feedbackService.getFeedbackById(feedbackId);
        return Result.success("反馈ID("+feedbackId+")获取反馈详情",feedback);
    }

    // 提交反馈
    @CheckPermission({"visitor"})
    @PostMapping("/add")
    public Result addFeedback(@RequestBody Feedback feedback) {
        feedbackService.addFeedback(feedback);
        return Result.success("反馈提交成功！");
    }

    // 删除反馈
    @CheckPermission({"visitor"})
    @DeleteMapping("/delete/{feedbackId}")
    public Result deleteFeedback(@PathVariable Integer feedbackId) {
        feedbackService.deleteFeedback(feedbackId);
        return Result.success("反馈删除成功！");
    }

    // 更新反馈
    @CheckPermission({"visitor"})
    @PutMapping("/update")
    public Result updateFeedback(@RequestBody Feedback feedback) {
        feedbackService.updateFeedback(feedback);
        return Result.success("反馈更新成功！");
    }
}
